<?php

class AllController extends DefaultModuleController {
	
	public function actionproduct() {
	
		$sqladd="";
		$page = max(1, getgpc('page'));
		
		$num = $this->ProductModel->count($sqladd);
		
		$multipage = $this->page($num, GODHOUSE_PPP3, $page, "all-product.htm");
		
		$productArr = $this->ProductModel->findAll($sqladd, $page, GODHOUSE_PPP3," productSort asc");
		
		//print_r($productArr);
		foreach($productArr as &$v) {
			$category =	$this->CategoryModel->findByPk($v['categoryId']);
			$v['categoryName'] = $category['cateName'];
			$v['userPrice'] = $this->userId ? number_format($v['ourPrice']*$this->getDiscount($v['upperparentId'], $v['parentId']), 2, '.', '') : '未登录';
			$v['contents'] = cutstr($v['content'], '20', '');
		}
		$oneArr = $this->CategoryModel->find("categoryId='$categoryId'");
		
		$this->header['title'];
		$this->view->assign('productArr', $productArr);
		$this->view->assign('multipage', $multipage);
		$this->view->assign('cateArr', $this->_showCategory());
		$this->view->assign('numCount', $num);
		$this->display('all_product');
		}	
	
	private function _showCategory($categoryId=0,$type='') {
		$listArr = $this->CategorysPublic->get_list(GODHOUSE_CATEGORY_PRODUCT, 2);
		$selectName = '';
		
		foreach ($listArr as $key => $val) {
			if($categoryId==$val['categoryId']) {
				$selectName = $val['cateName'];
			}			
			if($val['level']==1) {
				$strArr = array();
				foreach ($listArr as $oval) {
					if($oval['parentId']==$val['categoryId']) {
						$strArr[] = array('categoryId' => $oval['categoryId'], '_cateName' => $oval['cateName'], 'cateName' => cutstr($oval['cateName'], 18, ''), 'productCount' => $oval['productCount']);
					}
				}
				$mlistArr[] = array('categoryId' => $val['categoryId'], 'cateName' => $val['cateName'], 'moreArr' => $strArr);
			}
        }
		return $type=='list'?array($mlistArr, $selectName):$mlistArr;
	}
		
	public function actionone() {
		$categoryId = getgpc(2);

		
		$page = max(1, getgpc('page'));
		$num = $this->ProductModel->count(" productNo='$categoryId' ");
		$multipage = $this->page($num, GODHOUSE_PPP3, $page, "all-product.htm");
		
		$productArr = $this->ProductModel->findAll(" productNo='$categoryId' ", $page, GODHOUSE_PPP3," productSort asc");
		
		//print_r($productArr);
		foreach($productArr as &$v) {
			$category =	$this->CategoryModel->findByPk($v['categoryId']);
			$v['categoryName'] = $category['cateName'];
			$v['userPrice'] = $this->userId ? number_format($v['ourPrice']*$this->getDiscount($v['upperparentId'], $v['parentId']), 2, '.', '') : '未登录';
			$v['contents'] = cutstr($v['content'], '20', '');
		}
		
		$oneArr = $this->CategoryModel->find("categoryId='$categoryId'");
		$this->header['title'];
		$this->view->assign('productNo', $v['productNo']);
		$this->view->assign('categoryName', "-".$v['categoryName']);
		$this->view->assign('productArr', $productArr);
		$this->view->assign('cateArr', $this->_showCategory());
		$this->view->assign('multipage', $multipage);
		$this->view->assign('numCount', $num);
		$this->display('s_product');
		}	
	
	}
	?>